package tw.com.hitevision.whiteboard.android.stateFile;

import android.os.Parcel;
import android.os.Parcelable;

import tw.com.hitevision.whiteboard.android.render.BaseItem;

public class BaseStateFile implements Parcelable {
    private String className;
    private boolean isSelected;
    private float x;
    private float y;
    private float width;
    private float height;
    private int color;
    private int index;
    private boolean lock;
    private float degree;
    private long id;

    public BaseStateFile(BaseItem baseItem) {
        this.isSelected = baseItem.isSelected();
        this.x = baseItem.getX();
        this.y = baseItem.getY();
        this.width = baseItem.getWidth();
        this.height = baseItem.getHeight();
        this.color = baseItem.getColor();
    }

    protected BaseStateFile(Parcel in) {
        className = in.readString();
        isSelected = in.readByte() != 0;
        x = in.readFloat();
        y = in.readFloat();
        width = in.readFloat();
        height = in.readFloat();
        color = in.readInt();
        lock = in.readByte() != 0;
        degree = in.readFloat();
        index = in.readInt();
        id = in.readLong();
    }

    public static final Creator<BaseStateFile> CREATOR = new Creator<BaseStateFile>() {
        @Override
        public BaseStateFile createFromParcel(Parcel in) {
            return new BaseStateFile(in);
        }

        @Override
        public BaseStateFile[] newArray(int size) {
            return new BaseStateFile[size];
        }
    };

    public void setSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setX(float x) {
        this.x = x;
    }

    public float getX() {
        return x;
    }

    public void setY(float y) {
        this.y = y;
    }

    public float getY() {
        return y;
    }

    public void setWidth(float width) {
        this.width = width;
    }

    public float getWidth() {
        return width;
    }

    public void setHeight(float height) {
        this.height = height;
    }

    public float getHeight() {
        return height;
    }

    public void setColor(int color) {
        this.color = color;
    }

    public int getColor() {
        return color;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getClassName() {
        return className;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(className);
        dest.writeByte((byte) (isSelected ? 1 : 0));
        dest.writeFloat(x);
        dest.writeFloat(y);
        dest.writeFloat(width);
        dest.writeFloat(height);
        dest.writeInt(color);
        dest.writeByte((byte) (lock ? 1 : 0));
        dest.writeFloat(degree);
        dest.writeInt(index);
        dest.writeLong(id);
    }
}
